<?php
//路由类
class Url extends Object{ 
    public function __construct(){
        $this->Url();
    }
    
    public function Url(){
        #TODO
    }

    public static function parse(){
        if (isset($_SERVER['PATH_INFO'])){
        //PATH_INFO模式
            $url=explode(URL_SEPA, trim($_SERVER['PATH_INFO'],'/'));
            //\W非"字"字符即除了数字、字母、下划线
            $app=empty($url[0])?'index':str_replace("/(\W+)/", '', array_shift($url));
            $act=empty($url[0])?'index':array_shift($url);
            for($i=0;$i<count($url);$i+=2){
                $_GET[$url[$i]]=$url[$i+1];
            }
        }else {
            //普通模式
            $app=empty($_GET['m'])?'index':$_GET['m'];
            $act=empty($_GET['a'])?'index':$_GET['a'];
        }
        self::run($app,$act);
    }

    private static function run($app,$act){
    	$app_file=APP_INC.'app/'.$app.'.php';
    	if (!is_file($app_file))
    	    exit('Missing controllor');
    	require $app_file;
    	define('APP',$app);
    	define('ACT',$act);
    	$app_class_name=ucfirst($app);
    	$_app=new $app_class_name;
    	//c($_app);
    	
    }

    
    




}